﻿using System.ComponentModel.Composition;
using Cubicle.Core.Interfaces;

namespace Cubicle.Core.Processors.Parameter
{
    [Export("Cubicle.Processors.Parameter.CorrectTypeParameterResolver", typeof(IProcessor<ParameterRequest>))]
    [ExportMetadata("Name", "CorrectTypeParameterResolver")]
    [ExportMetadata("Description", "Recognizes if the parameter is already of the correct type.")]
    public class CorrectTypeParameterResolver : ConditionalProcessor<ParameterRequest>
    {
        #region Overrides of Processor<ParameterRequest>

        public override bool Condition(ParameterRequest request)
        {
            return request.TargetType.IsAssignableFrom(request.SourceType);
        }

        public override ParameterRequest ConditionalProcess(ParameterRequest request)
        {
            request.Complete(request.Source);
            return request;
        }

        #endregion
    }
}